package xupt.se.ttms.view.seat;

import java.awt.Color;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import org.w3c.dom.css.ElementCSSInlineStyle;

import xupt.se.ttms.model.Customer;
import xupt.se.ttms.model.Studio;
import xupt.se.ttms.service.CustomerSrv;
import xupt.se.ttms.service.SeatSrv;
import xupt.se.ttms.service.StudioSrv;
import xupt.se.ttms.view.employee.Employee_MainUITmpl;
import xupt.se.ttms.view.tmpl.Login;
import xupt.se.ttms.model.Seat;

import java.awt.Insets;


public class SeatUpdateUI{

	public static JLabel b2;
	public static JLabel c2;
	public static JLabel d2;
	public static JLabel e2;
	public static JLabel f2;
	public static JFrame frame;
	public static Seat seat1=null;
	public static String comboBoxselect=""; 
	public  SeatUpdateUI(String user,Seat seat2)
	{
		frame = new JFrame();
		this.seat1=seat2;
		frame.setSize(850,500);
		frame.setTitle("修改座位");
		frame.setBounds(0, 0, 850, 500);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setResizable(false);
		frame.setLocationRelativeTo(null);
		ImageIcon icon=new ImageIcon("img/logo.png");
		JLabel x = new JLabel(icon);
		icon.setImage(icon.getImage().getScaledInstance(850,70,Image.SCALE_DEFAULT));
		JPanel a=new JPanel();
		a.setBackground(Color.decode("#FFe4c4"));
		a.setLayout(null);
		x.setBounds(0,0,850,70);
		a.add(x);
		frame.add(a);
		JLabel a1=new JLabel("修改座位");
		a1.setBounds(400,80,100,25);
		a.add(a1);
		JLabel b1=new JLabel("座位ID:");
		b1.setBounds(300,130,50,25);
		a.add(b1);
		b2=new JLabel(String.valueOf(this.seat1.getSeat_id()));
		b2.setBounds(350,130,200,25);
		a.add(b2);
		JLabel c1=new JLabel("演出厅ID:");
		c1.setBounds(300,160,50,25);
		a.add(c1);
		c2=new JLabel(String.valueOf(this.seat1.getStudio_id()));
		c2.setBounds(350,160,200,25);
		a.add(c2);
		JLabel d1=new JLabel("行号：");
		d1.setBounds(300,190,50,25);
		a.add(d1);
		d2=new JLabel(String.valueOf(this.seat1.getRow()));
		d2.setBounds(350,190,200,25);
		a.add(d2);
		JLabel e1=new JLabel("列号：");
		e1.setBounds(300,220,50,25);
		a.add(e1);
		e2=new JLabel(String.valueOf(this.seat1.getCol()));
		e2.setBounds(350,220,200,25);
		a.add(e2);
		JLabel f1=new JLabel("状态：");
		f1.setBounds(300,250,50,25);
		a.add(f1);
		JComboBox<String> comboBox=new JComboBox<>();
		comboBox.addItem("已售");
		comboBox.addItem("未售");
		comboBox.addItem("正常");
		comboBox.addItem("损坏");
		comboBox.setBounds(350,250,200,25);
		ComboxListen comboxListen=new ComboxListen();
		comboBox.addItemListener(comboxListen);
		comboBox.setSelectedItem(this.seat1.getState());
		a.add(comboBox);
	
			
		
	
		JButton enter=new JButton("确认修改");
		enter.setBounds(350,290,90,30);
		enter.setFocusPainted(false);
		enter.setMargin(new Insets(0,0,0,0));
		enter.setContentAreaFilled(false);
		enter.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent Event) {
			
				comboBoxselect=comboBox.getSelectedItem().toString();
		
				Seat seat=new Seat();
				seat.setSeat_id(seat1.getSeat_id());
				seat.setStudio_id(seat1.getStudio_id());
				seat.setRow(seat1.getRow());
				seat.setCol(seat1.getCol());
				seat.setState(comboBoxselect);
				
				SeatSrv seatSrv=new SeatSrv();
				
				try {
					boolean b=seatSrv.modify(seat);
					if(Employee_MainUITmpl.jTable!=null)
					{
						Employee_MainUITmpl.jTable.updateUI();
					}
					//JOptionPane.showConfirmDialog(null, "添加成功");
					frame.dispose();
					Employee_MainUITmpl employee_MainUITmpl=new Employee_MainUITmpl(user);
				
				} catch (Exception e) {
					// TODO 自动生成的 catch 块
					e.printStackTrace();
				}
					
			}
		});
		a.add(enter);
		JButton enter1=new JButton("返回");
		enter1.setBounds(460,290,90,30);
		enter1.setFocusPainted(false);
		enter1.setMargin(new Insets(0,0,0,0));
		enter1.setContentAreaFilled(false);
		enter1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent Event) {
				frame.dispose();
				Employee_MainUITmpl employee_MainUITmpl=new Employee_MainUITmpl(user);
			}
		});
		a.add(enter1);
		frame.setVisible(true);
		frame.setLayout(null);
		
		
	}
	class ComboxListen implements ItemListener
	{
		
		@Override
		public void itemStateChanged(ItemEvent e) {
			// TODO 自动生成的方法存根
			comboBoxselect=e.getItem().toString();
			
		}
		
	}

}
